﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SocialMediaEntry.cs" company="Catel development team">
//   Copyright (c) 2008 - 2012 Catel development team. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Catwitter.Models
{
    using System;
    using Catel;

    /// <summary>
    /// Social media entry object.
    /// </summary>
    public class SocialMediaEntry : ISocialMediaEntry
    {
        #region Constructor & destructor
        /// <summary>
        /// Initializes a new instance of the <see cref="SocialMediaEntry"/> class.
        /// </summary>
        /// <param name="photo">The photo, is allowed to be null.</param>
        /// <param name="author">The author.</param>
        /// <param name="message">The message.</param>
        /// <param name="timestamp">The timestamp.</param>
        /// <param name="url">The URL.</param>
        /// <param name="provider">The provider name.</param>
        /// <exception cref="ArgumentException">when <paramref name="author"/> is <c>null</c> or empty.</exception>
        /// <exception cref="ArgumentException">when <paramref name="message"/> is <c>null</c> or empty.</exception>
        /// <exception cref="ArgumentException">when <paramref name="url"/> is <c>null</c> or empty.</exception>
        public SocialMediaEntry(Uri photo, string author, string message, DateTime timestamp, string url,
                                string provider)
        {
            Argument.IsNotNullOrWhitespace("author", author);
            Argument.IsNotNullOrWhitespace("message", message);
            Argument.IsNotNullOrWhitespace("url", url);

            Photo = photo;
            Author = author;
            Message = message;
            Timestamp = timestamp;
            Url = url;
            Provider = provider;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the photo of the account that posted this entry.
        /// </summary>
        /// <value>The photo of the account that posted this entry.</value>
        public Uri Photo { get; private set; }
        #endregion

        #region ISocialMediaEntry Members
        /// <summary>
        /// Gets the name of the author.
        /// </summary>
        /// <value>The name of the author.</value>
        public string Author { get; private set; }

        /// <summary>
        /// Gets the message content.
        /// </summary>
        /// <value>The message content.</value>
        public string Message { get; private set; }

        /// <summary>
        /// Gets the message preview, which are the first 144 characters of a message.
        /// </summary>
        /// <value>The message preview.</value>
        public string MessagePreview
        {
            get
            {
                if (Message.Length > 144)
                {
                    return Message.Substring(0, 141) + "...";
                }

                return Message;
            }
        }

        /// <summary>
        /// Gets the timestamp when this entry was posted.
        /// </summary>
        /// <value>The timestamp when this entry was posted.</value>
        public DateTime Timestamp { get; private set; }

        /// <summary>
        /// Gets the URL for the real content.
        /// </summary>
        /// <value>The URL for the real content.</value>
        public string Url { get; private set; }

        /// <summary>
        /// Gets the name of the provider.
        /// </summary>
        /// <value>The provider name.</value>
        public string Provider { get; private set; }
        #endregion
    }
}